home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / IOInterface / deltaDialog.icl < prev    next >
Encoding:
Modula Implementation  |  1997-04-25  |  26.9 KB  |  693 lines  |  [TEXT/3PRM]

  1. implementation module deltaDialog;
  2.  
  3.  
  4. import StdClass;
  5. import    StdInt, StdBool, StdString;
  6. from    deltaMenu        import EnableMenuSystem, DisableMenuSystem;
  7. from    windows            import SelectWindow;
  8. from    menus            import EnableItem, DisableItem, CheckItem;
  9. from    OS_utilities    import SysBeep;
  10. from    dialogs            import GetDItem, SetIText;
  11. import    dialogAccess, dialogDevice, dialogUpdate, dialogAbout, dialogInternal;
  12.  
  13.  
  14. ::    DialogChange *s :== (DialogState s (IOState s)) -> DialogState s (IOState s);
  15.  
  16. DeltaDialogError :: String String -> .x;
  17. DeltaDialogError f error = Error f "deltaDialog" error;
  18.     
  19.  
  20. /*    Opening/Closing of dialogs and notices. A beep is a very simple notice. */
  21.  
  22. OpenDialog :: !(DialogDef s (IOState s)) !(IOState s) -> IOState s;
  23. OpenDialog (AboutDialog _ _ _ _) io = io;
  24. OpenDialog dDef io
  25. |    id == AboutDialogID                = io;
  26. |    modalActive && alreadyOpen        = io`;
  27. |    modalActive                        = IOStateAddInactiveDialog dRep1 io2;
  28. |    alreadyOpen                        = IOStateSetDialogs dialogs` io3;
  29.                                     = IOStateAddDialog dRep3 io4;
  30.     where {
  31.         (modalActive, ptr, io1)    = IOStateModalDialogActive io;
  32.         (dialogs, io`)            = IOStateGetDialogs io1;
  33.         id                        = GetDialogDefId dDef;
  34.         (alreadyOpen,_)            = GetDialog id dialogs;
  35.         (tb, io``)                = IOStateGetToolbox io`;
  36.         (dRep1,tb1)                = OpenAnyDialog Modeless ptr dDef tb;
  37.         io2                        = IOStateSetToolbox tb1 io``;
  38.         (_,dialogs`)            = SetDialogInFront id dialogs;
  39.         io3                        = IOStateSetToolbox (ActivateDialog dialogs` tb) io``;
  40.         (dRep3,tb3)                = OpenAnyDialog Modeless (-1) dDef tb;
  41.         io4                        = IOStateSetToolbox (ForceDialogUpdate dRep3 tb3) io``;
  42.     };
  43.  
  44. OpenModalDialog    :: !(DialogDef *s (IOState *s)) !*s !(IOState *s) -> (!*s, !IOState *s);
  45. OpenModalDialog dDef s io = DoModalDialog dDef s io;
  46.  
  47. CloseDialog    :: !DialogId !(IOState s) -> IOState s;
  48. CloseDialog id io
  49. |    not found    = io`;
  50.                 = DeactivateDialog dRep io`;
  51.     where {
  52.         (found, dRep, io`) = IOStateRemoveDialog id io;
  53.     };
  54.  
  55. CloseActiveDialog :: !(IOState s) -> IOState s;
  56. CloseActiveDialog io = DeviceCloseDialog io;
  57.  
  58. OpenNotice :: !NoticeDef !*s !(IOState *s) -> (!NoticeButtonId, !*s, !IOState *s);
  59. OpenNotice notice s io
  60.     = (buttonid,s,io`)
  61.     where {
  62.         (buttonid,io`)    = DoNotice notice io;
  63.     };
  64.  
  65. Beep :: !(IOState s) -> IOState s;
  66. Beep io = IOStateChangeToolbox (SysBeep 1) io;
  67.  
  68.  
  69. /*    Get(Active)DialogInfo returns the DialogInfo for the indicated dialog.
  70.     The boolean indicates whether the indicated dialog exists. When it is False
  71.     a dummy DialogInfo is returned. */
  72.  
  73. GetDialogInfo :: !DialogId !(IOState s) -> (!Bool, !DialogInfo, !IOState s);
  74. GetDialogInfo id io = IOStateGetDialogInfo id io;
  75.  
  76. GetActiveDialogInfo :: !(IOState s) -> (!Bool, !DialogInfo, !IOState s);
  77. GetActiveDialogInfo io = IOStateGetActiveDialogInfo io;
  78.  
  79.  
  80. /*    Enabling/Disabling of dialog items */
  81.  
  82. EnableDialogItems :: ![DialogItemId] !(DialogState s (IOState s)) -> DialogState s (IOState s);
  83. EnableDialogItems itids dstate
  84.     =    CreateDialogState (SetDialogItemsAbility Able itids (UnpackDialogState dstate));
  85.  
  86. DisableDialogItems :: ![DialogItemId] !(DialogState s (IOState s)) -> DialogState s (IOState s);
  87. DisableDialogItems itids dstate
  88.     =    CreateDialogState (SetDialogItemsAbility Unable itids (UnpackDialogState dstate));
  89.  
  90. SetDialogItemsAbility :: !SelectState ![DialogItemId] !(!DialogRep s (IOState s), !Toolbox)
  91.     ->    (!DialogRep s (IOState s), !Toolbox);
  92. SetDialogItemsAbility abty ids ((DialogH i t m r popups items f, ptr), tb)
  93.     =     ((DialogH i t m r popups items1 f, ptr), tb1);
  94.     where {
  95.         (items1, tb1) = SetItemsAbility popups abty ids items ptr 1 tb;
  96.     };
  97.  
  98. SetItemsAbility    :: ![PopUpHandle] !SelectState ![DialogItemId] ![DialogItem s (IOState s)]
  99.                     !DialogPtr !Int !Toolbox -> (![DialogItem s (IOState s)], !Toolbox);
  100. SetItemsAbility _ _ [] items _ _ tb
  101.     =    (items, tb);
  102. SetItemsAbility pps abty ids [but=:DialogButton id ps tt ab bf : rest] ptr nr tb
  103. |    not toBeSet || SelectStateEqual abty ab
  104.     =    ([but : setrest], tb1);
  105.     =    ([DialogButton id ps tt abty bf : setrest], ToggleHilite abty ptr nr tb1);
  106.     where {
  107.         (setrest, tb1)    = SetItemsAbility pps abty ids` rest ptr (inc nr) tb;
  108.         (toBeSet, ids`)    = RemoveCheckInt ids id;
  109.     };
  110. SetItemsAbility pps abty ids [RadioButtons id ps rc di buts : rest] ptr nr tb
  111.     =    ([RadioButtons id ps rc di buts` : setrest], tb2);
  112.     where {
  113.         (ids`,buts`,nr`,tb1)= SetRadioButtonsAbility abty ids buts ptr nr tb;
  114.         (setrest, tb2)        = SetItemsAbility pps abty ids` rest ptr nr` tb1;
  115.     };
  116. SetItemsAbility pps abty ids [CheckBoxes id ps rc boxes : rest] ptr nr tb
  117.     =    ([CheckBoxes id ps rc boxes` : setrest], tb2);
  118.     where {
  119.         (ids`,boxes`,nr`,tb1)    = SetCheckBoxesAbility abty ids boxes ptr nr tb;
  120.         (setrest,tb2)            = SetItemsAbility pps abty ids` rest ptr nr` tb1;
  121.     };
  122. SetItemsAbility pps abty ids [icon=:DialogIconButton id pos dom look ab bf : rest] ptr nr tb
  123. |    not toBeSet || SelectStateEqual abty ab
  124.     =    ([icon : setrest], tb1);
  125.     =    ([DialogIconButton id pos dom look abty bf : setrest], tb2);
  126.     where {
  127.         (setrest,tb1)    = SetItemsAbility pps abty ids` rest ptr nr tb;
  128.         tb2                = RedrawIconOrControl pos dom (look abty) ptr tb1;
  129.         (toBeSet, ids`)    = RemoveCheckInt ids id;
  130.     };
  131. SetItemsAbility pps abty ids [ctrl=:Control id pos dom ab state look cf df : rest] ptr nr tb
  132. |    not toBeSet || SelectStateEqual abty ab
  133.     =    ([ctrl : setrest], tb1);
  134.     =    ([Control id pos dom abty state look cf df : setrest], tb2);
  135.     where {
  136.         (setrest,tb1)    = SetItemsAbility pps abty ids` rest ptr nr tb;
  137.         tb2                = RedrawIconOrControl pos dom (look abty state) ptr tb1;
  138.         (toBeSet,ids`)    = RemoveCheckInt ids id;
  139.     };
  140. SetItemsAbility popups abty ids [popup=:DialogPopUp id ps ab di pitems : rest] ptr nr tb
  141. |    not toBeSet || SelectStateEqual abty ab
  142.     =    ([DialogPopUp id ps ab   di pitems` : setrest], tb2);
  143.     =    ([DialogPopUp id ps abty di pitems` : setrest], tb3); 
  144.     where {
  145.         (ids``,pitems`,tb1)    = SetPopUpItemsAbility abty ids pitems menu 1 tb;
  146.         (setrest,tb2)        = SetItemsAbility popups abty ids`` rest ptr nr tb1;
  147.         tb3                    = DrawPopUpAbility ps abty ptr tb2;
  148.         (toBeSet,ids`)        = RemoveCheckInt ids id;
  149.         (pi,menu)            = GetPopUpHandle id popups;
  150.     };
  151. SetItemsAbility pps abty ids [item : rest] ptr nr tb
  152.     =    ([item : setrest], tb`);
  153.     where {
  154.         (setrest, tb`) = SetItemsAbility pps abty ids rest ptr (inc nr) tb;
  155.     };
  156. SetItemsAbility _ _ _ items _ _ tb = (items, tb);
  157.  
  158. SetPopUpItemsAbility :: !SelectState ![DialogItemId] ![RadioItemDef s (IOState s)]
  159.                         !MacMenuHandle !Int !Toolbox
  160.     ->    (![DialogItemId], ![RadioItemDef s (IOState s)], !Toolbox);
  161. SetPopUpItemsAbility abty ids [item=:RadioItem id tt ab df : rest] menu nr tb
  162. |    not toBeSet || SelectStateEqual abty ab
  163.     =    (ids``,[item:rest`],tb`);
  164.     =    (ids``,[RadioItem id tt abty df : rest`],SetMenuItemAbility abty menu nr tb`);
  165.     where {
  166.         (ids``,rest`,tb`)   = SetPopUpItemsAbility abty ids` rest menu (inc nr) tb;
  167.         (toBeSet, ids`)        = RemoveCheckInt ids id;
  168.     };
  169. SetPopUpItemsAbility _ ids items _ _ tb = (ids,items,tb);
  170.  
  171. SetRadioButtonsAbility :: !SelectState ![DialogItemId] ![RadioItemDef s (IOState s)]
  172.                             !DialogPtr !Int !Toolbox
  173.     -> (![DialogItemId], ![RadioItemDef s (IOState s)], !Int, !Toolbox);
  174. SetRadioButtonsAbility abty ids [but=:RadioItem id tt ab df : rest] ptr nr tb
  175. |    not toBeSet || SelectStateEqual abty ab
  176.     =    (ids``,[but:rest`],nr`,tb`);
  177.     =    (ids``,[RadioItem id tt abty df : rest`],nr`,ToggleHilite abty ptr nr tb`);
  178.     where {
  179.         (ids``,rest`,nr`,tb`)    = SetRadioButtonsAbility abty ids` rest ptr (inc nr) tb;
  180.         (toBeSet, ids`)            = RemoveCheckInt ids id;
  181.     };
  182. SetRadioButtonsAbility _ ids [] _ nr tb = (ids,[],nr,tb);
  183.  
  184. SetCheckBoxesAbility :: !SelectState ![DialogItemId] ![CheckBoxDef s (IOState s)]
  185.                         !DialogPtr !Int !Toolbox
  186.     -> (![DialogItemId], ![CheckBoxDef s (IOState s)], !Int, !Toolbox);
  187. SetCheckBoxesAbility abty ids [but=:CheckBox id tt ab ms df : rest] ptr nr tb
  188. |    not toBeSet || SelectStateEqual abty ab
  189.     =    (ids``,[but:rest`],nr`,tb`);
  190.     =    (ids``,[CheckBox id tt abty ms df : rest`],nr`,ToggleHilite abty ptr nr tb`);
  191.     where {
  192.         (ids``,rest`,nr`,tb`)    = SetCheckBoxesAbility abty ids` rest ptr (inc nr) tb;
  193.         (toBeSet,ids`)            = RemoveCheckInt ids id;
  194.     };
  195. SetCheckBoxesAbility _ ids [] _ nr tb = (ids,[],nr,tb);
  196.  
  197. SetMenuItemAbility :: !SelectState !MacMenuHandle !Int !Toolbox -> Toolbox;
  198. SetMenuItemAbility Able   menu nr tb = EnableItem  menu nr tb;
  199. SetMenuItemAbility Unable menu nr tb = DisableItem menu nr tb;
  200.  
  201. ToggleHilite :: !SelectState !DialogPtr !Int !Toolbox -> Toolbox;
  202. ToggleHilite Able   ptr nr tb = Unhilite ptr nr tb;
  203. ToggleHilite Unable ptr nr tb = Hilite   ptr nr tb;
  204.  
  205.  
  206. /*    Marking/Unmarking of check boxes. */
  207.  
  208. MarkCheckBoxes :: ![DialogItemId] !(DialogState s (IOState s)) -> DialogState s (IOState s);
  209. MarkCheckBoxes itids dstate
  210.     =    CreateDialogState (SetCheckBoxesMark Mark itids (UnpackDialogState dstate));
  211.  
  212. UnmarkCheckBoxes :: ![DialogItemId] !(DialogState s (IOState s)) -> DialogState s (IOState s);
  213. UnmarkCheckBoxes itids dstate
  214.     =    CreateDialogState (SetCheckBoxesMark NoMark itids (UnpackDialogState dstate));
  215.  
  216. SetCheckBoxesMark :: !MarkState ![DialogItemId] !(!DialogRep s (IOState s),!Toolbox)
  217.     ->    (!DialogRep s (IOState s),!Toolbox);
  218. SetCheckBoxesMark mark ids ((DialogH i t m r p items f, ptr), tb)
  219.     =     ((DialogH i t m r p items1 f, ptr), tb1);
  220.     where {
  221.         (items1,tb1) = SetMark mark ids items ptr 1 tb;
  222.     };
  223.  
  224. SetMark :: !MarkState ![DialogItemId] ![DialogItem s (IOState s)] !DialogPtr !Int !Toolbox
  225.     ->    (![DialogItem s (IOState s)], !Toolbox);
  226. SetMark _ [] items _ _ tb = (items,tb);
  227. SetMark mark ids [CheckBoxes id ps rc boxes : rest] ptr nr tb
  228.     =    ([CheckBoxes id ps rc boxes` : setrest], tb2);
  229.     where {
  230.         (ids`,boxes`,nr`,tb1)    = CheckBoxesMark mark ids boxes ptr nr tb;
  231.         (setrest,tb2)            = SetMark mark ids` rest ptr nr` tb1;
  232.     };
  233. SetMark mark ids [item=: RadioButtons id ps rc di buts : rest] ptr nr tb
  234.     =    ([item : setrest],tb1);
  235.     where {
  236.         (setrest,tb1) = SetMark mark ids rest ptr (nr+Length_new buts) tb;
  237.     };
  238. SetMark mark ids [popup=:DialogPopUp id ps ab di bs : rest] ptr nr tb
  239.     =    ([popup : setrest],tb1);
  240.     where {
  241.         (setrest,tb1) = SetMark mark ids rest ptr nr tb;
  242.     };
  243. SetMark mark ids [icon=:DialogIconButton id pos dom look ab bf : rest] ptr nr tb
  244.     =    ([icon : setrest],tb1);
  245.     where {
  246.         (setrest,tb1) = SetMark mark ids rest ptr nr tb;
  247.     };
  248. SetMark mark ids [ctrl=:Control id pos dom ab state look cf df : rest] ptr nr tb
  249.     =    ([ctrl : setrest], tb1);
  250.     where {
  251.         (setrest,tb1) = SetMark mark ids rest ptr nr tb;
  252.     };
  253. SetMark mark ids [item : rest] ptr nr tb
  254.     =    ([item : setrest], tb1);
  255.     where {
  256.         (setrest,tb1) = SetMark mark ids rest ptr (inc nr) tb;
  257.     };
  258. SetMark _ _ items _ _ tb = (items,tb);
  259.  
  260. CheckBoxesMark :: !MarkState ![DialogItemId] ![CheckBoxDef s (IOState s)] !DialogPtr !Int !Toolbox
  261.     -> (![DialogItemId], ![CheckBoxDef s (IOState s)], !Int, !Toolbox);
  262. CheckBoxesMark mark ids [but=:CheckBox id tt ab ms df : rest] ptr nr tb
  263. |    not to_be_set || MarkEqual mark ms
  264.     =    (ids``,[but:rest`],nr`,tb1);
  265. |    Checked mark
  266.     =    (ids``,[but` : rest`],nr`,SetCtlValue h 1 tb2);
  267.     =    (ids``,[but` : rest`],nr`,SetCtlValue h 0 tb2);
  268.     where {
  269.         (ids``,rest`,nr`,tb1)    = CheckBoxesMark mark ids` rest ptr (inc nr) tb;
  270.         (it,h,r,tb2)            = GetDItem ptr nr tb1;
  271.         but`                    = CheckBox id tt ab mark df;
  272.         (to_be_set,ids`)        = RemoveCheckInt ids id;
  273.     };
  274. CheckBoxesMark _ ids items _ nr tb = (ids,items,nr,tb);
  275.  
  276.  
  277. /*    Press a radio button (and unpress the rest). */
  278.  
  279. SelectDialogRadioItem :: !DialogItemId !(DialogState s (IOState s)) -> DialogState s (IOState s);
  280. SelectDialogRadioItem itid dstate
  281.     =    CreateDialogState (PressRadioBut itid (UnpackDialogState dstate));
  282.  
  283. PressRadioBut :: !DialogItemId !(DialogRep s (IOState s), !Toolbox)
  284.     ->    (!DialogRep s (IOState s), !Toolbox);
  285. PressRadioBut id ((DialogH i t m r popups items f, ptr), tb)
  286.     =    ((DialogH i t m r popups items1 f, ptr), tb1);
  287.     where {
  288.         (items1,tb1) = PressRadio popups id items ptr 1 tb;
  289.     };
  290.  
  291. PressRadio :: ![PopUpHandle] !DialogItemId ![DialogItem s (IOState s)] !DialogPtr !Int !Toolbox
  292.     ->    (![DialogItem s (IOState s)],!Toolbox);
  293. PressRadio popups rid [popup=:DialogPopUp id pos ab di pits : rest] ptr nr tb
  294. |    not in_group
  295.     =    ([popup : rest1],tb1);
  296.     =    ([DialogPopUp id pos ab rid pits : rest], tb2);
  297.     where {
  298.         (in_group,onr,inr,title)= InDialogPopUpMenu 0 0 "" di rid pits 1;
  299.         (rest1,tb1)                = PressRadio popups rid rest ptr nr tb;
  300.         tb2                        = RedrawPopUpItemText pos title ptr
  301.                                     (CheckItem menu inr True
  302.                                     (CheckItem menu onr False tb1));
  303.         (pi,menu)                = GetPopUpHandle id popups;
  304.     };
  305. PressRadio pps rid [item=:RadioButtons id ps rc di buts : rest] ptr nr tb
  306. |    not in_group
  307.     =    ([item : rest1], tb1);
  308.     =    ([RadioButtons id ps rc rid buts : rest], tb2);
  309.     where {
  310.         (rest1,tb1)        = PressRadio pps rid rest ptr nr` tb;
  311.         tb2                = UpdateRadioButtons rid buts ptr nr tb;
  312.         (in_group,nr`)    = InRadioGroup rid buts nr;
  313.     };
  314. PressRadio pps rid [item=: CheckBoxes id ps rc boxes : rest] ptr nr tb
  315.     =    ([item : rest1],tb1);
  316.     where {
  317.         (rest1,tb1) = PressRadio pps rid rest ptr (nr+Length_new boxes) tb;
  318.     };
  319. PressRadio pps rid [icon=:DialogIconButton id pos dom look ab bf : rest] ptr nr tb
  320.     =    ([icon : rest1],tb1);
  321.     where {
  322.         (rest1,tb1) = PressRadio pps rid rest ptr nr tb;
  323.     };
  324. PressRadio pps rid [ctrl=:Control id pos dom ab state look cf df : rest] ptr nr tb
  325.     =    ([ctrl : rest1],tb1);
  326.     where {
  327.         (rest1,tb1) = PressRadio pps rid rest ptr nr tb;
  328.     };
  329. PressRadio pps rid [item : rest] ptr nr tb
  330.     =    ([item : rest1],tb1);
  331.     where {
  332.         (rest1,tb1) = PressRadio pps rid rest ptr (inc nr) tb;
  333.     };
  334. PressRadio _ _ items _ _ tb = (items,tb);
  335.  
  336. InDialogPopUpMenu :: !Int !Int !ItemTitle !DialogItemId !DialogItemId ![RadioItemDef s (IOState s)]
  337.                      !Int
  338.     ->    (!Bool, !Int, !Int, !ItemTitle);
  339. InDialogPopUpMenu oldnr newnr title oldid newid [RadioItem id tt ab df : rest] inr
  340. |    newmatch && oldnr > 0    = (True,oldnr,inr,tt);
  341. |    oldmatch && newnr > 0    = (True,inr,newnr,title);
  342. |    newmatch                = InDialogPopUpMenu oldnr inr   tt    oldid newid rest (inc inr);
  343. |    oldmatch                = InDialogPopUpMenu inr   newnr title oldid newid rest (inc inr);
  344.                             = InDialogPopUpMenu oldnr newnr title oldid newid rest (inc inr);
  345.     where {
  346.         newmatch = id == newid;
  347.         oldmatch = id == oldid;
  348.     };
  349. InDialogPopUpMenu _ _ _ _ _ _ _ = (False,0,0,"");
  350.  
  351. UpdateRadioButtons :: !DialogItemId ![RadioItemDef s (IOState s)] !DialogPtr !Int !Toolbox -> Toolbox;
  352. UpdateRadioButtons rid [RadioItem id tt ab df : rest] ptr nr tb
  353. |    rid == id    = UpdateRadioButtons rid rest ptr (inc nr) (SetCtlValue h 1 tb1);
  354.                 = UpdateRadioButtons rid rest ptr (inc nr) (SetCtlValue h 0 tb1);
  355.     where {
  356.         (it,h,r,tb1) = GetDItem ptr nr tb;
  357.     };
  358. UpdateRadioButtons _ _ _ _ tb = tb;
  359.  
  360. InRadioGroup :: !DialogItemId ![RadioItemDef s (IOState s)] !Int -> (!Bool, !Int);
  361. InRadioGroup id1 [RadioItem id2 tt ab df : rest] nr
  362. |    id1 == id2    = (True,nr);
  363.                 = InRadioGroup id1 rest (inc nr);
  364. InRadioGroup _ _ nr = (False,nr);
  365.  
  366.  
  367. /*    Change the contents of an editable or a dynamic text field. */
  368.  
  369. ChangeEditText    :: !DialogItemId !String !(DialogState s (IOState s)) -> DialogState s (IOState s);
  370. ChangeEditText itid text dstate = ChangeDialogItem itid (ChangeEText text) dstate;
  371.  
  372. ChangeEText :: !String !DialogPtr !Int !(!DialogItem s (IOState s),!Toolbox)
  373.     ->    (!DialogItem s (IOState s), !Toolbox);
  374. ChangeEText text ptr nr (EditText id ps wd nl _,tb)
  375.     =    (EditText id ps wd nl text, SetIText h text tb1);
  376.     where {
  377.         (it,h,r,tb1) = GetDItem ptr nr tb;
  378.     };
  379. ChangeEText _ _ _ item_tb = item_tb;
  380.  
  381. ChangeDynamicText :: !DialogItemId !String !(DialogState s (IOState s)) -> DialogState s (IOState s);
  382. ChangeDynamicText itid text dstate = ChangeDialogItem itid (ChangeDText text) dstate;
  383.  
  384. ChangeDText :: !String !DialogPtr !Int !(!DialogItem s (IOState s),!Toolbox)
  385.     ->    (!DialogItem s (IOState s), !Toolbox);
  386. ChangeDText text ptr nr (DynamicText id ps wd _, tb)
  387.     =    (DynamicText id ps wd text, SetIText h text tb1);
  388.     where {
  389.         (it,h,r,tb1) = GetDItem ptr nr tb;
  390.     };
  391. ChangeDText _ _ _ item_tb = item_tb;
  392.  
  393.  
  394. /*    Change the IconLook and redraw the IconButton */
  395.  
  396. ChangeIconLook :: !DialogItemId !IconLook !(DialogState s (IOState s)) -> DialogState s (IOState s);
  397. ChangeIconLook itid ilook dstate = ChangeDialogItem itid (SetIconLook ilook) dstate;
  398.  
  399. SetIconLook    :: !IconLook !DialogPtr !Int !(!DialogItem s (IOState s),!Toolbox)
  400.     ->    (!DialogItem s (IOState s), !Toolbox);
  401. SetIconLook ilook ptr nr (DialogIconButton id pos dom look abty bf,tb)
  402.     =    (DialogIconButton id pos dom ilook abty bf, RedrawIconOrControl pos dom (ilook abty) ptr tb);
  403. SetIconLook _ _ _ item_tb = item_tb;
  404.  
  405.  
  406. /*    Change the ControlState and redraw the Control */
  407.  
  408. ChangeControlState :: !DialogItemId !ControlState !(DialogState s (IOState s))
  409.     -> DialogState s (IOState s);
  410. ChangeControlState cid cstate dstate = ChangeDialogItem cid (SetControlState cstate) dstate;
  411.  
  412. SetControlState    :: !ControlState !DialogPtr !Int !(!DialogItem s (IOState s),!Toolbox)
  413.     ->    (!DialogItem s (IOState s), !Toolbox);
  414. SetControlState cstate ptr nr (Control id pos dom ab state look cf df,tb)
  415.     =    (Control id pos dom ab cstate look cf df,RedrawIconOrControl pos dom (look ab cstate) ptr tb);
  416. SetControlState _ _ _ item_tb = item_tb;
  417.  
  418.  
  419. /*    Change the ControlLook and redraw the Control */
  420.  
  421. ChangeControlLook :: !DialogItemId !ControlLook !(DialogState s (IOState s))
  422.     -> DialogState s (IOState s);
  423. ChangeControlLook cid clook dstate = ChangeDialogItem cid (SetControlLook clook) dstate;
  424.  
  425. SetControlLook :: !ControlLook !DialogPtr !Int !(!DialogItem s (IOState s),!Toolbox)
  426.     ->    (!DialogItem s (IOState s), !Toolbox);
  427. SetControlLook clook ptr nr (Control id pos dom ab state look cf df,tb)
  428.     =    (Control id pos dom ab state clook cf df,RedrawIconOrControl pos dom (clook ab state) ptr tb);
  429. SetControlLook _ _ _ item_tb = item_tb;
  430.  
  431.  
  432. /*    Change the ControlFeel, but dont redraw the Control */
  433.  
  434. ChangeControlFeel :: !DialogItemId !ControlFeel !(DialogState s (IOState s))
  435.     -> DialogState s (IOState s);
  436. ChangeControlFeel cid cfeel dstate = ChangeDialogItem cid (SetControlFeel cfeel) dstate;
  437.  
  438. SetControlFeel :: !ControlFeel !DialogPtr !Int !(!DialogItem s (IOState s),!Toolbox)
  439.     ->    (!DialogItem s (IOState s), !Toolbox);
  440. SetControlFeel cfeel ptr nr (Control id pos dom ab cs cl _ df,tb)
  441.     =    (Control id pos dom ab cs cl cfeel df, tb);
  442. SetControlFeel _ _ _ item_tb = item_tb;
  443.  
  444.  
  445. /*    Change the DialogFunction of a check box, a radio button or a user-defined control. */
  446.  
  447. ChangeDialogFunction :: !DialogItemId !(DialogFunction s (IOState s)) !(DialogState s (IOState s))
  448.     ->    DialogState s (IOState s);
  449. ChangeDialogFunction itid dfunc dstate
  450.     =    CreateDialogState (SetDFunction itid dfunc (UnpackDialogState dstate));
  451.  
  452. SetDFunction :: !DialogItemId !(DialogFunction s (IOState s)) !(!DialogRep s (IOState s),!Toolbox)
  453.     ->    (!DialogRep s (IOState s),!Toolbox);
  454. SetDFunction id dfunc ((DialogH i t m r p items f, ptr), tb)
  455.     =    ((DialogH i t m r p (SetDFunc id dfunc items) f, ptr), tb);
  456.  
  457. SetDFunc :: !DialogItemId  !(DialogFunction s (IOState s)) ![DialogItem s (IOState s)]
  458.     ->    [DialogItem s (IOState s)];
  459. SetDFunc itid dfunc [item=:DialogPopUp id ps ab di pits : rest]
  460. |    found    = [DialogPopUp id ps ab di pits` : rest];
  461.             = [item : SetDFunc itid dfunc rest];
  462.     where {
  463.         (found, pits`) = SetRadioItemsDFunc itid dfunc pits;
  464.     };
  465. SetDFunc itid dfunc [item=:CheckBoxes id ps rc boxes : rest]
  466. |    found    = [CheckBoxes id ps rc boxes` : rest];
  467.             = [item : SetDFunc itid dfunc rest];
  468.     where {
  469.         (found,boxes`) = SetCheckBoxesDFunc itid dfunc boxes;
  470.     };
  471. SetDFunc itid dfunc [item=:RadioButtons id ps rc di buts : rest]
  472. |    found    = [RadioButtons id ps rc di buts` : rest];
  473.             = [item : SetDFunc itid dfunc rest];
  474.     where {
  475.         (found,buts`) = SetRadioItemsDFunc itid dfunc buts;
  476.     };
  477. SetDFunc itid dfunc [item=:Control id ps pd ab cs cl cf _ : rest]
  478. |    itid == id    = [Control id ps pd ab cs cl cf dfunc : rest];
  479.                 = [item : SetDFunc itid dfunc rest];
  480. SetDFunc itid dfunc [item : rest]
  481.     =    [item : SetDFunc itid dfunc rest];
  482. SetDFunc _ _ items = items;
  483.  
  484. SetCheckBoxesDFunc :: !DialogItemId  !(DialogFunction s (IOState s)) ![CheckBoxDef s (IOState s)]
  485.     ->    (!Bool, ![CheckBoxDef s (IOState s)]);
  486. SetCheckBoxesDFunc itid dfunc [box=:CheckBox id tt ab ms df : rest]
  487. |    itid == id    = (True, [CheckBox id tt ab ms dfunc : rest]);
  488.                 = (found, [box : rest`]);
  489.     where {
  490.         (found,rest`) = SetCheckBoxesDFunc itid dfunc rest;
  491.     };
  492. SetCheckBoxesDFunc _ _ items = (False,items);
  493.  
  494. SetRadioItemsDFunc :: !DialogItemId  !(DialogFunction s (IOState s)) ![RadioItemDef s (IOState s)]
  495.     -> (!Bool, ![RadioItemDef s (IOState s)]);
  496. SetRadioItemsDFunc itid dfunc [but=:RadioItem id tt ab df : rest]
  497. |    itid == id    = (True, [RadioItem id tt ab dfunc : rest]);
  498.                 = (found, [but : rest`]);
  499.     where {
  500.         (found,rest`) = SetRadioItemsDFunc itid dfunc rest;
  501.     };
  502. SetRadioItemsDFunc _ _ items = (False,items);
  503.  
  504.  
  505. /*    Change the ButtonFunction of a DialogButton or DialogIconButton. */
  506.  
  507. ChangeButtonFunction :: !DialogItemId !(ButtonFunction s (IOState s)) !(DialogState s (IOState s))
  508.     ->    DialogState s (IOState s);
  509. ChangeButtonFunction itid bfunc dstate = ChangeDialogItem itid (SetButtonFunction bfunc) dstate;
  510.  
  511. SetButtonFunction :: !(ButtonFunction s (IOState s)) !DialogPtr !Int
  512.         !(!DialogItem s (IOState s),!Toolbox)
  513.     ->     (!DialogItem s (IOState s),!Toolbox);
  514. SetButtonFunction bfunc ptr nr (DialogButton id ps tt ab _,tb)
  515.     =  (DialogButton id ps tt ab bfunc,tb);
  516. SetButtonFunction bfunc ptr nr (DialogIconButton id ps pd il ab _,tb)
  517.     =  (DialogIconButton id ps pd il ab bfunc,tb);
  518. SetButtonFunction _ _ _ item_tb = item_tb;
  519.  
  520.  
  521. /*    Change Set/Reset button function of a PropertyDialog. The id of the Set button
  522.     is always -1, the id of the Reset button is always -2 (see dialogDef.icl). */
  523.  
  524. ChangeSetFunction :: !(SetFunction s (IOState s)) !(DialogState s (IOState s))
  525.    -> DialogState s (IOState s);
  526. ChangeSetFunction setfunc dstate = ChangeButtonFunction (-1) setfunc dstate;
  527.  
  528. ChangeResetFunction :: !(ResetFunction s (IOState s)) !(DialogState s (IOState s))
  529.    -> DialogState s (IOState s);
  530. ChangeResetFunction resetfunc dstate = ChangeButtonFunction (-2) resetfunc dstate;
  531.  
  532.  
  533. /* DialogStateGetDialogInfo returns the DialogInfo corresponding to
  534.    the DialogState given to it. */
  535.  
  536. DialogStateGetDialogInfo :: !(DialogState s (IOState s))
  537.     -> (!DialogInfo, !DialogState s (IOState s));
  538. DialogStateGetDialogInfo dState
  539.     =    (DialogHandleToDialogInfo dH, CreateDialogState (dRep1,tb1));
  540.     where {
  541.         (dRep1,tb1)    = RetrieveEditTexts (UnpackDialogState dState);
  542.         (dH,_)        = dRep1;
  543.     };
  544.  
  545.  
  546. /*    Functions that retrieve information from the DialogInfo. */
  547.  
  548. GetEditText :: !DialogItemId !DialogInfo -> String;
  549. GetEditText tid dinfo
  550.     =    RetrieveEditText tid edits;
  551.     where {
  552.         (edits,_,_,_) = DialogInfoToItemInfo dinfo;
  553.     };
  554.  
  555. RetrieveEditText :: !DialogItemId ![(DialogItemId,String)] -> String;
  556. RetrieveEditText tid [(id,text):rest]
  557. |    id == tid    = text;
  558.                 = RetrieveEditText tid rest;
  559. RetrieveEditText tid _
  560.     =    DeltaDialogError "GetEditText" ("No EditText item found with id " +++ toString tid);
  561.  
  562. GetSelectedRadioItemId :: !DialogItemId !DialogInfo -> DialogItemId;
  563. GetSelectedRadioItemId tid dinfo
  564.     =    RetrieveRadioItemId tid radios;
  565.     where {
  566.         (_,radios,_,_) = DialogInfoToItemInfo dinfo;
  567.     };
  568.  
  569. RetrieveRadioItemId :: !DialogItemId ![(DialogItemId,DialogItemId)] -> DialogItemId;
  570. RetrieveRadioItemId tid [(id,di):rest]
  571. |    id == tid    = di;
  572.                 = RetrieveRadioItemId tid rest;
  573. RetrieveRadioItemId tid _
  574.     =    DeltaDialogError "GetSelectedRadioItemId"
  575.                         ("No RadioButtons or DialogPopUp item found with id " +++ toString tid);
  576.  
  577. CheckBoxesMarked :: !DialogItemId !DialogInfo -> [(DialogItemId,Bool)];
  578. CheckBoxesMarked tid dinfo
  579.     =    RetrieveCheckMarks tid checks;
  580.     where {
  581.         (_,_,checks,_) = DialogInfoToItemInfo dinfo;
  582.     };
  583.  
  584. RetrieveCheckMarks :: !DialogItemId ![(DialogItemId,[(DialogItemId,Bool)])] -> [(DialogItemId,Bool)];
  585. RetrieveCheckMarks tid [(id,boxes):rest]
  586. |    id == tid    = boxes;
  587.                 = RetrieveCheckMarks tid rest;
  588. RetrieveCheckMarks tid _
  589.     =    DeltaDialogError "CheckBoxesMarked" ("No CheckBoxes item found with id " +++ toString tid);
  590.  
  591. CheckBoxMarked :: !DialogItemId !DialogInfo -> Bool;
  592. CheckBoxMarked tid dinfo
  593.     =    RetrieveCheckMark tid checks;
  594.     where {
  595.         (_,_,checks,_) = DialogInfoToItemInfo dinfo;
  596.     };
  597.  
  598. RetrieveCheckMark :: !DialogItemId ![(DialogItemId,[(DialogItemId,Bool)])] -> Bool;
  599. RetrieveCheckMark tid [(id,boxes):rest]
  600. |    found    = mark;
  601.             = RetrieveCheckMark tid rest;
  602.     where {
  603.         (found,mark) = FindCheckMark tid boxes;
  604.     };
  605. RetrieveCheckMark tid _
  606.     =    DeltaDialogError "CheckBoxMarked" ("No CheckBox item found with id " +++ toString tid);
  607.  
  608. FindCheckMark :: !DialogItemId ![(DialogItemId,Bool)] -> (Bool,Bool);
  609. FindCheckMark tid [(id,mark):rest]
  610. |    id == tid    = (True,mark);
  611.                 = FindCheckMark tid rest;
  612. FindCheckMark _ _ = (False,False);
  613.  
  614. GetControlState    :: !DialogItemId !DialogInfo -> ControlState;
  615. GetControlState tid dinfo
  616.     =    RetrieveControlState tid ctrls;
  617.     where {
  618.         (_,_,_,ctrls) = DialogInfoToItemInfo dinfo;
  619.     };
  620.  
  621. RetrieveControlState :: !DialogItemId ![(DialogItemId,ControlState)] -> ControlState;
  622. RetrieveControlState tid [(id,state):rest]
  623. |    id == tid    = state;
  624.                 = RetrieveControlState tid rest;
  625. RetrieveControlState tid _
  626.     =    DeltaDialogError "GetControlState" ("No Control item found with id " +++ toString tid);
  627.  
  628.  
  629. /*    Change the dialog with the specified id according to the list of change functions. */
  630.  
  631. ChangeDialog :: !DialogId ![DialogChange s] !(IOState s) -> IOState s;
  632. ChangeDialog did changes ioState
  633. |    not found    = ioState1;
  634.                 = IOStateReplaceDialog did drep1 (IOStateSetToolbox tb1 ioState2);
  635.     where {
  636.         (found,drep,ioState1)    = IOStateGetDialog did ioState;
  637.         (tb, ioState2)            = IOStateGetToolbox ioState1;
  638.         (drep1,tb1)    = UnpackDialogState (ApplyDialogChanges changes (CreateDialogState (drep,tb)));
  639.     };
  640.  
  641. ApplyDialogChanges :: ![DialogChange s] !(DialogState s (IOState s)) -> DialogState s (IOState s);
  642. ApplyDialogChanges [change : rest]    dstate = ApplyDialogChanges rest (change dstate);
  643. ApplyDialogChanges _                dstate = dstate;
  644.  
  645.  
  646. //
  647. //    Change a dialog item according to the function (used internally)
  648. //
  649.     
  650. ::    ItemChange *s
  651.     :==    DialogPtr -> Int
  652.                   -> (DialogItem s (IOState s),!Toolbox)
  653.                   -> (DialogItem s (IOState s),!Toolbox);
  654.  
  655.     
  656. ChangeDialogItem :: !DialogItemId !(ItemChange *s) !(DialogState *s (IOState *s))
  657.     ->    DialogState *s (IOState *s);
  658. ChangeDialogItem itid change dstate
  659.     =    CreateDialogState (ChangeDItem itid change (UnpackDialogState dstate));
  660.  
  661. ChangeDItem :: !DialogItemId !(ItemChange *s) !(!DialogRep *s (IOState *s),!Toolbox)
  662.     ->    (!DialogRep *s (IOState *s),!Toolbox);
  663. ChangeDItem id change ((DialogH i t m r p items f, ptr), tb)
  664.     =    ((DialogH i t m r p items1 f, ptr), tb1);
  665.     where {
  666.         (items1,tb1) = ChangeItem id ptr 1 change items tb;
  667.     };
  668.  
  669. ChangeItem :: !DialogItemId !DialogPtr !Int !(ItemChange *s) ![DialogItem *s (IOState *s)] !Toolbox
  670.     ->    (![DialogItem *s (IOState *s)],!Toolbox);
  671. ChangeItem itid ptr nr change [item : items] tb
  672. |    itid == id
  673.     =    ([item` : items],tb1);
  674.     =    ([item  : items1],tb2);
  675.     where {
  676.         (item`,tb1)    = change ptr nr (item,tb);
  677.         (id,add)    = GetDialogItemId item;
  678.         (items1,tb2)= ChangeItem itid ptr (nr + add) change items tb;
  679.     };
  680. ChangeItem _ _ _ _ [] tb = ([],tb);
  681.  
  682. GetDialogItemId    :: !(DialogItem s (IOState s)) -> (!DialogItemId, Int);
  683. GetDialogItemId (DialogButton     id _ _ _ _)        = (id,1);
  684. GetDialogItemId (DialogIconButton id _ _ _ _ _)        = (id,0);
  685. GetDialogItemId (StaticText       id _ _)            = (id,1);
  686. GetDialogItemId (DynamicText      id _ _ _)            = (id,1);
  687. GetDialogItemId (EditText         id _ _ _ _)        = (id,1);
  688. GetDialogItemId (DialogPopUp      id _ _ _ _)        = (id,0);
  689. GetDialogItemId (CheckBoxes       id _ _ boxes)        = (id,Length_new boxes);
  690. GetDialogItemId (RadioButtons     id _ _ _ buts)    = (id,Length_new buts);
  691. GetDialogItemId (Control          id _ _ _ _ _ _ _)    = (id,0);
  692. GetDialogItemId _ = DeltaDialogError "GetDialogItemId" "Unknown item";
  693.